﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace thinger.GenericTeach
{
    public class Course
    {
        public string CourseName { get; set; }
        public int Period { get; set; }
    }
    public class Teacher
    {
        public Teacher() { }  //无参数构造方法

        public string Name { get; set; }
        public int CourseCount { get; set; }//授课数量
    }

    public class MyGenericClass1<T1,T2,T3> 
        where T1:struct 
        where T2:class 
        where T3:new()
    {
        public List<T2> courseList { get; set; }
        public T3 publisher { get; set; }

        public MyGenericClass1()
        {
            this.courseList = new List<T2>();
            this.publisher = new T3();  //如果没有泛型约束，是不能直接这样使用的。
        }

        public T2 BuyCourse(T1 index)
        {
            dynamic _index = index;
            //return this.courseList[index];//在编译阶段解析不通过，直接写是错误的
            return this.courseList[_index];//dynamic是在运行的时候解析对象的类型，在编译阶段不解析
        }
    }
}